/**
 * Author: Dmitry Ustimov
 * Date: 6/1/13
 * Time: 10:08 PM
 */

package com.gmail.dmitryustimov.ms.java7.chain_of_responsibility.mod.mod_multy_type_actionmap.demo.handlers6_request1;

import com.gmail.dmitryustimov.ms.java7.patternslib.chain_of_responsibility.multyevent.HandleAction;
import com.gmail.dmitryustimov.ms.java7.patternslib.chain_of_responsibility.multyevent.Handler;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class CocreteHandler5<T extends Request> extends Handler<T> {

    private String name;
    protected int level;
    private BigDecimal sum = BigDecimal.valueOf(0);

    public CocreteHandler5(String name, int level) {
        this.level = level;
        this.name = name;

        Map<Class<? extends T>, HandleAction<? extends T>> actions = new HashMap<>();
        actions.put((Class<T>)Request1.class, (HandleAction<T>)this.new Request1Action());
        init(actions);
    }

    private class Request1Action implements HandleAction<Request1> {
        @Override
        public void handle(Request1 request) {
            sum.add(BigDecimal.valueOf(1));
        }
    }

    @Override
    public Boolean canHandle(T request) {
        return request.getRequestLevel() <= level;
    }
}
